package think.bank;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.Scanner;

public class CustomerClient {
	public static void init() throws Exception {
		try (Socket soc = new Socket("127.0.0.1", 8686);
				// 控制台输入
				Scanner in = new Scanner(System.in);
				//BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
				// 获取socket输入
				BufferedReader reader = new BufferedReader(new InputStreamReader(soc.getInputStream()));
				// 获取socket输出
				PrintWriter pw = new PrintWriter(soc.getOutputStream());) {
			while (true) {
				String input = in.nextLine();
				//System.out.println(input);
				pw.println(input);
				pw.flush();
				//System.out.println("客户端输入/发送:" + input);

				String read = reader.readLine();
				System.out.println("客户端接受:" + read);
				if ("over".equals(input)) {
					break;
				}
			}
		}
	}

	public static void main(String[] args) throws Exception {
		CustomerClient.init();
	}
}
